package org.bozo.im.service.protocols.xmpp.stanza.processor.bind;

import java.io.IOException;

import org.bozo.im.service.Constants;
import org.bozo.im.service.protocols.xmpp.XMPPSession;
import org.bozo.im.service.protocols.xmpp.stanza.Stanza;
import org.bozo.im.service.protocols.xmpp.stanza.processor.StanzaProcessor;
import org.bozo.im.service.protocols.xmpp.stanza.processor.jabber.client.IqStanzaProcessor;
import org.bozo.im.service.protocols.xmpp.stanza.processor.stream.FeaturesStanzaProcessor;
import org.bozo.im.service.protocols.xmpp.stanza.task.bind.BindTask;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

public class BindStanzaProcessor extends StanzaProcessor {

	private static BindStanzaProcessor mInstance;
	
	private BindStanzaProcessor() {}
	
	public static BindStanzaProcessor getInstance() {
		if (mInstance == null)
			mInstance = new BindStanzaProcessor();
		return mInstance;
	}
	
	@Override
	public Stanza getStanza() {
		return Stanza.BIND_BIND;
	}

	@Override
	public void processStanza(XmlPullParser pParser, XMPPSession pSession, StanzaProcessor pParentProcessor) throws XmlPullParserException, IOException {
		
		if (pParentProcessor == FeaturesStanzaProcessor.getInstance()) {
			// ---------------------------------------------------------------------------------------
			Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.xmpp.stanza.processor.bind.BindStanzaProcessor.processStanza ---------- Starting binding request");
			// ---------------------------------------------------------------------------------------
			pSession.getTaskProcessor().pushTask(new BindTask(pSession.getId()));
			
		} else if (pParentProcessor == IqStanzaProcessor.getInstance()) {
			super.processStanza(pParser, pSession, pParentProcessor);
		
		} else {
			// ---------------------------------------------------------------------------------------
			Log.d(Constants.ACTIVITY_TAG, "org.bozo.im.xmpp.stanza.processor.bind.BindStanzaProcessor.processStanza ---------- I don't know what to do with this Stanza");
			// ---------------------------------------------------------------------------------------
		}
	}

}
